﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:ADU_ASSIGN
	/// </summary>
	public partial class ADU_ASSIGN : BaseDAL<GSLMS.Entity.TB_ADU_ASSIGN>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public ADU_ASSIGN()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_ADU_ASSIGN model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_ASSIGNBY", model.ASSIGNBY),
								new OracleParameter("P_ASSIGNTIME", model.ASSIGNTIME),
								new OracleParameter("P_FLOWUSER", model.FLOWUSER)};
  
			for (int i = 0; i < 5; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
                OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_audit.proc_assign_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_ADU_ASSIGN model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_ASSIGNBY", model.ASSIGNBY),
								new OracleParameter("P_ASSIGNTIME", model.ASSIGNTIME),
								new OracleParameter("P_FLOWUSER", model.FLOWUSER)};
  
			for (int i = 0; i < 5; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_adu_assign_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_adu_assign_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_ADU_ASSIGN DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_ADU_ASSIGN model = new GSLMS.Entity.TB_ADU_ASSIGN();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["ASSIGNBY"]!=null && dr["ASSIGNBY"].ToString()!="")
				{
					model.ASSIGNBY=dr["ASSIGNBY"].ToString();
				}
				if(dr["ASSIGNTIME"]!=null && dr["ASSIGNTIME"].ToString()!="")
				{
					model.ASSIGNTIME=DateTime.Parse(dr["ASSIGNTIME"].ToString());
				}
				if(dr["FLOWUSER"]!=null && dr["FLOWUSER"].ToString()!="")
				{
					model.FLOWUSER=dr["FLOWUSER"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_ADU_ASSIGN GetByID(long ID)
		{
			GSLMS.Entity.TB_ADU_ASSIGN sModel = new GSLMS.Entity.TB_ADU_ASSIGN();
			string sql = "";
			sql = "select * from TB_ADU_ASSIGN where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_ADU_ASSIGN> GetList(GSLMS.Entity.TB_ADU_ASSIGN searchParam)
		{
			var list=new List<GSLMS.Entity.TB_ADU_ASSIGN>();
			DataTable dt = null;
			string tblName = "TB_ADU_ASSIGN";
			string sqlWhere="";
			string strSort="";
			int pageSize=15;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;

            //是否计算总数
            countFlag = (searchParam.Pagination.ReCount != null && searchParam.Pagination.ReCount) ? 1 : 0;
            pageSize = (searchParam.Pagination.PageSize != null && searchParam.Pagination.PageSize > 0) ? searchParam.Pagination.PageSize : 15;
            pageIndex = (searchParam.Pagination.CurrentIndex != null && searchParam.Pagination.CurrentIndex > 0) ? searchParam.Pagination.CurrentIndex : 1;
            strSort = searchParam.StrSort;

			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_ADU_ASSIGN model = new GSLMS.Entity.TB_ADU_ASSIGN();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

